package com.hotkid.ceo.jetpack.myjetpackmvvm.data.http.interceptor

import com.hotkid.ceo.jetpack.myjetpackmvvm.common.MyConfig
import com.yechaoa.yutilskt.SpUtil
import okhttp3.Interceptor
import okhttp3.Response

/**
 * ClassName:ReceivedCookiesInterceptor
 * Package:com.hotkid.ceo.jetpack.myjetpackmvvm.data.http.interceptor
 * Description:
 * @date:2021/3/23 5:27 PM
 * @author:774169396@qq.com
 */
class ReceivedCookiesInterceptor :Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val response=chain.proceed(chain.request())
        val cookies=HashSet<String>()
        var headers = response.headers("Set-Cookie")
        if (headers.isNullOrEmpty()) {
            headers.forEach {
                cookies.add(it)
            }
            SpUtil.setStringSet(MyConfig.COOKIE,cookies)
        }

       return response
    }


}